package com.yulongtian.offers.day202302;

import java.util.Stack;

/**
 * 可
 *
 * @author yulongTian
 * @create 2023-02-03 21:34
 */
public class Test03 {
    public static void main(String[] args) {
        System.out.println(maxDepth("(1+(2*3)+((8)/4))+1"));
    }

    public static int maxDepth(String s) {
//        char[] chars = s.toCharArray();
        int ans = 0;
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(') {
                stack.push(c);
            }
            if (c == ')') {
                if (!stack.empty()) {
                    stack.pop();
                }
            }
            ans = Math.max(ans, stack.size());
        }
        if (!stack.empty()) {
            ans -= stack.size();
        }
        return ans;
    }
}
